package com.zhy.sunmi;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.molo17.customizablecalendar.library.components.CustomizableCalendar;
import com.molo17.customizablecalendar.library.interactors.AUCalendar;
import com.molo17.customizablecalendar.library.model.Calendar;
import com.zhy.sunmi.fragment.staff.CalendarViewInteractor;

import org.joda.time.DateTime;

import io.reactivex.disposables.CompositeDisposable;


public class MainActivity2 extends AppCompatActivity {
    CustomizableCalendar customizableCalendar;
    CompositeDisposable subscriptions;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main2);
        customizableCalendar=findViewById(R.id.customizable_calendar);
        subscriptions = new CompositeDisposable();
        DateTime today = new DateTime();

        // setting up first and last month that must be showed in the calendar
        DateTime firstMonth = today.plusMonths(-3).withDayOfMonth(1);
        DateTime lastMonth = today.plusMonths(-1).withDayOfMonth(1);

        // create the Calendar obj and setting it up with some configs like:
        // - first selected day
        // - last selected day
        // - multiple selection

        final Calendar calendar = new Calendar(firstMonth, lastMonth);

        calendar.setFirstSelectedDay(today.plusMonths(-3).plusDays(-1));
        // if you don't want the multiple selection mode just skip the 2 lines below
        calendar.setLastSelectedDay(today.plusMonths(-3).plusDays(-1));
        calendar.setMultipleSelection(true);



        // create a ViewInteractor obj needed to interact with the CustomizableCalendar
        final CalendarViewInteractor calendarViewInteractor = new CalendarViewInteractor(getApplicationContext());

        // create an AUCalendar object (a Calendar wrapper that operates as a singleton and provides all the updates)
        AUCalendar auCalendar = AUCalendar.getInstance(calendar);

        calendarViewInteractor.updateCalendar(calendar);
        subscriptions.add(
                auCalendar.observeChangesOnCalendar()
                        .subscribe(changeSet -> calendarViewInteractor.updateCalendar(calendar))
        );

        // injecting the ViewInteractor to the CustomizableCalendar View
        customizableCalendar.injectViewInteractor(calendarViewInteractor);

    }








}

